﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ExceptionMessageBoxLibrary
{
    /// <summary>
    /// MessageBox to view Exception with exception details.
    /// </summary>
    public partial class ExceptionMessageBoxView : Window, IExceptionMessageBoxView
    {
        MessageBoxResult m_MessageBoxResult = MessageBoxResult.None;

        public ExceptionMessageBoxView()
        {
            InitializeComponent();
        }

        #region IExceptionMessageBoxView Members

        public ExceptionMessageBoxViewModel Model
        {
            get
            {
                return (ExceptionMessageBoxViewModel)DataContext;
            }
            set
            {
                DataContext = value;
            }
        }

        public MessageBoxResult ShowExceptionMessage()
        {
            return ShowExceptionMessage(null);
        }

        public MessageBoxResult ShowExceptionMessage(Window owner)
        {
            Owner = owner;
            this.m_MessageBoxResult = MessageBoxResult.None;
            this.ShowDialog();

            return this.m_MessageBoxResult;
        }

        #endregion


        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            this.m_MessageBoxResult = MessageBoxResult.OK;
            this.DialogResult = true;
        }

        private void yesButton_Click(object sender, RoutedEventArgs e)
        {
            this.m_MessageBoxResult = MessageBoxResult.Yes;
            this.DialogResult = true;
        }

        private void noButton_Click(object sender, RoutedEventArgs e)
        {
            this.m_MessageBoxResult = MessageBoxResult.No;
            this.DialogResult = false;
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.m_MessageBoxResult = MessageBoxResult.Cancel;
            this.DialogResult = false;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {           
            this.m_MessageBoxResult = MessageBoxResult.Cancel;
            this.DialogResult = false;
        }

    }
}
